/*
 * Copyright (C) 2010-2025 Structr GmbH
 *
 * This file is part of Structr <http://structr.org>.
 *
 * Structr is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * Structr is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Structr.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.structr.test.core.traits.definitions;

import org.structr.common.PropertyView;
import org.structr.core.entity.Relation;
import org.structr.core.graph.NodeInterface;
import org.structr.core.property.*;
import org.structr.core.traits.NodeTraitFactory;
import org.structr.core.traits.TraitsInstance;
import org.structr.core.traits.definitions.AbstractNodeTraitDefinition;
import org.structr.core.traits.definitions.GraphObjectTraitDefinition;
import org.structr.core.traits.definitions.NodeInterfaceTraitDefinition;

import java.util.Date;
import java.util.Map;
import java.util.Set;

public class TestOneTraitDefinition extends AbstractNodeTraitDefinition {

	public TestOneTraitDefinition() {
		super("TestOne");
	}

	@Override
	public Set<PropertyKey> createPropertyKeys(final TraitsInstance traitsInstance) {

		final PropertyKey<Integer>                 anInt              = new IntProperty("anInt").indexed().indexedWhenEmpty();
		final PropertyKey<Long>                    aLong              = new LongProperty("aLong").indexed().indexedWhenEmpty();
		final PropertyKey<Double>                  aDouble            = new DoubleProperty("aDouble").indexed().indexedWhenEmpty();
		final PropertyKey<Date>                    aDate              = new ISO8601DateProperty("aDate").indexed().indexedWhenEmpty();
		final PropertyKey<String>                  anEnum             = new EnumProperty("anEnum", newSet("One", "Two", "Three", "Four")).indexed();
		final PropertyKey<String>                  aString            = new StringProperty("aString").indexed().indexedWhenEmpty().fulltextIndexed();
		final PropertyKey<Boolean>                 aBoolean           = new BooleanProperty("aBoolean").indexed();
		final PropertyKey<String>                  testString         = new StringProperty("testString");
		final PropertyKey<String>                  anotherString      = new StringProperty("anotherString");
		final PropertyKey<String>                  replaceString      = new StringProperty("replaceString");
		final PropertyKey<String>                  cleanTestString    = new StringProperty("cleanTestString");
		final PropertyKey<String>                  stringWithQuotes   = new StringProperty("stringWithQuotes");
		final PropertyKey<Integer>                 setTestInteger1    = new IntProperty("setTestInteger1");
		final PropertyKey<Integer>                 setTestInteger2    = new IntProperty("setTestInteger2");
		final PropertyKey<Integer>                 setTestInteger3    = new IntProperty("setTestInteger3");
		final PropertyKey<String>                  alwaysNull         = new StringProperty("alwaysNull");
		final PropertyKey<String>                  doResult           = new StringProperty("doResult");
		final PropertyKey<String>                  stringWithDefault  = new StringProperty("stringWithDefault").defaultValue("default value").indexedWhenEmpty();
		final PropertyKey<NodeInterface>           testTwo            = new EndNode(traitsInstance, "testTwo",  "OneTwoOneToOne");
		final PropertyKey<NodeInterface>           testTwo2           = new StartNode(traitsInstance, "testTwo",  "TwoOneOneToOne");
		final PropertyKey<NodeInterface>           testThree          = new EndNode(traitsInstance, "testThree", "OneThreeOneToOne");
		final PropertyKey<NodeInterface>           testFour           = new EndNode(traitsInstance, "testFour",  "OneFourOneToOne");
		final Property<NodeInterface>              oneToOneTestOneOut = new EndNode(traitsInstance, "oneToOneTestOne",    "OneOneOneToOne");
		final Property<NodeInterface>              oneToOneTestOneIn  = new StartNode(traitsInstance, "oneToOneTestOne",    "OneOneOneToOne");
		final Property<NodeInterface>              oneToOneTestSix    = new StartNode(traitsInstance, "oneToOneTestSix",    "SixOneOneToOne");
		final PropertyKey<Iterable<NodeInterface>> manyToManyTestSixs = new StartNodes(traitsInstance, "manyToManyTestSixs", "SixOneManyToMany");
		final PropertyKey<String>                  aCreateString      = new StringProperty("aCreateString").indexed();
		final PropertyKey<Integer>                 aCreateInt         = new IntProperty("aCreateInt").indexed();
		final PropertyKey<String[]>                aStringArray       = new ArrayProperty("aStringArray", String.class).indexed();
		final PropertyKey<Boolean>                 isValid            = new BooleanProperty("isValid");

		return newSet(
			anInt,
			aLong,
			aDouble,
			aDate,
			anEnum,
			aString,
			aBoolean,
			testString,
			anotherString,
			replaceString,
			cleanTestString,
			stringWithQuotes,
			setTestInteger1,
			setTestInteger2,
			setTestInteger3,
			alwaysNull,
			doResult,
			stringWithDefault,
			testTwo,
			testTwo2,
			testThree,
			testFour,
			oneToOneTestOneIn,
			oneToOneTestOneOut,
			oneToOneTestSix,
			manyToManyTestSixs,
			aCreateString,
			aCreateInt,
			aStringArray,
			isValid
		);
	}

	@Override
	public Map<String, Set<String>> getViews() {

		return Map.of(

			PropertyView.Public,
			newSet(
					NodeInterfaceTraitDefinition.NAME_PROPERTY, "anInt", "aDouble", "aLong", "aDate", GraphObjectTraitDefinition.CREATED_DATE_PROPERTY, "aString", "anotherString", "aBoolean", "anEnum", "stringWithDefault", "aStringArray"
			),

			PropertyView.Protected,
			newSet(
				NodeInterfaceTraitDefinition.NAME_PROPERTY, "anInt", "aString"
			)
		);
	}

	@Override
	public Map<Class, NodeTraitFactory> getNodeTraitFactories() {
		return Map.of();
	}

	@Override
	public Relation getRelation() {
		return null;
	}
}
